<?php
require_once("../../../config.inc.php");
require_once("../../../app/_inc/include.php");
require_once("../_inc/_mbAppDomValue.php");

$errMsg = "";
$objUser = $_SESSION[USEROBJ];
$aDataArea = $objUser->getDataArea();
$sSQL = "SELECT a.*, e.description AS e_description, d.description AS d_description, " .
			"    d.domain AS d_domain, d.type, d.length AS d_length, d.decimals AS d_decimals" .
			" FROM domain d" .
			" INNER JOIN attribute a ON d.domain = a.domain " .
			" INNER JOIN entity e ON e.entity = a.entity " .
			" WHERE d.domain='".sxRAS('dom')."' ORDER BY a.entity, a.attribute";
$query = $objSDAO->query($sSQL);
$row = $objSDAO->fetch();

//output HTML
$aOpz = array("kMenu"=>'dam.dom');
echo(headerHTML($aOpz));
echo(bodyHTML($aOpz));
//output comandi
$aCmd = array(
					"back"=>array("pag"=>$objUser->getHistory(-1,false),
										"title"=>"",
										"text"=>$objUser->getHistoryText(-1),
										"perm"=>"R")
					);
echo(commandsHTML($aCmd));	
//output dei dati
echo("<table class=\"tabl01\" width=\"100%\" cellpadding=\"3\" cellspacing=\"2\">\n");
echo("<tr>" .
		"<td class=\"tabh01\" >Domain</td>" .
		"<td class=\"text01\"colspan='6'>".sxHE($row['d_domain']).' - '.sxHE($row['d_description'])."</td>" .
	"</tr>\n");
echo("<tr><td class=\"titl01\" colspan=\"7\">List of attribute</td>" .
	"</tr>\n");
echo("<tr>" .
		"<td class=\"tabh01\" width=\"18%\">"._t("Entity")."</td>" .
		"<td class=\"tabh01\" width=\"15%\">"._t("Attribute")."</td>" .
		"<td class=\"tabh01\" width=\"30%\">"._t("Description")."</td>" .
		"<td class=\"tabh01\" width=\"15%\">"._t("Format.")."</td>" .
		"<td class=\"tabh01\" width=\"30%\">"._t("Default")."</td>" .
		"<td class=\"tabh01\" width=\"1%\" align='center'>PK</td>" .
		"<td class=\"tabh01\" width=\"1%\" align='center'>I</td>" .
	"</tr>\n");
$numElem=0;
while($row){
	$numElem ++;
	$format = '???';
	if ($row['d_length'] == 0) {
		$length = $row['length'];
		$decimals = $row['decimals'];
	} else {
		$length = $row['d_length'];
		$decimals = $row['d_decimals'];
	}
	switch ($row["type"]) {
		case 'integer' :
		case 'date' :
		case 'date-time' :
		case 'text' :
		case 'long-text' :
		case 'blob' :
		case 'boolean' :
			$format = $row["type"];
			break;
		case 'string' :
		case 'variable-string' :
			$format = $row["type"]."(".$length.")";
			break;
		case 'number' :
		default :
			$format = $row["type"]."(".$length.",".$decimals.")";
			break;
	}
	echo("<tr>" .
			"<td class=\"text01\"><a class=\"text01\" ".
				goToPag("../enty/entityView.php?da=".substr($row["entity"],0,4)."&ent=".$row["entity"]."&xsn=".XSN).
				" title=\"Entity view\">".$row["entity"]."</a></td>" .
			"<td class=\"text01\"><a class=\"text01\" ".
				goToPag("../attr/attributeView.php?da=".substr($row["entity"],0,4)."&ent=".$row["entity"]."&att=".$row["attribute"]."&xsn=".XSN).
				" title=\"Attribute view\">".$row["attribute"]."</a></td>" .
			"<td class=\"text01\">".sxHE($row["description"])."</td>" .
			"<td class=\"text01\">".$format."</td>" .
			"<td class=\"text01\">".
			(($row["primary_key"]=='X')?"(auto-increment)":sxHE($row["default_value"]))."</td>" .
			"<td class=\"text01\" align='center'>".(($row["primary_key"]!='N')?'*':'&nbsp;')."</td>" .
			"<td class=\"text01\" align='center'>".(($row["indexed"]=='Y')?'*':'&nbsp;')."</td>" .
		"</tr>\n");
	$row = $objSDAO->fetch();
}
if($numElem == 0) {
	echo("<tr>" .
				"<td class=\"text01\" colspan=\"9\">".
					_t("no attribute associated with '%s'",$row['d_domain'])." <b>$entity</b></td>".
			"</tr>\n");
	echo("</table>\n");
}
echo(commandsHTML($aCmd));
echo(footerHTML());
